package com.teachoa.bean;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

public class Task extends Model<Task> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3138506543589914046L;
	
	public static final Task dao = new Task();
	
	public List<Task> findTasksByProcessId(String processId) {
		String sql = "select * from task where process_id = ? order by node asc";
		return dao.find(sql, processId);
	}
	
	public List<Task> findTasksByProcessIdAndNode(String processId, int node) {
		String sql = "select * from task where process_id = ? and node = ? order by node asc";
		return dao.find(sql, processId, node);
	}
	
	public int getMaxNodeByProcessId(String processId) {
		return Db.findFirst("select max(node) as maxIndex from task where process_id = ?", processId).getInt("maxIndex");
	}
	
	public int getTotalNumByPidAndNode(String processId, int node) {
		String sql = "select count(*) as totalNode from task where process_id = ? and node = ?";
		return Db.findFirst(sql, processId, node).getLong("totalNode").intValue();
	}

}
